<template>
    <div class="feeBox">
        <el-breadcrumb separator="->" class="bread">
            <el-breadcrumb-item><a href="/">首页</a></el-breadcrumb-item>
            <el-breadcrumb-item>费用预算</el-breadcrumb-item>
        </el-breadcrumb>
        <h1>请输入产品信息：</h1>
        <br>
        <div>厘米/千克：</div>
        <div class="cm">
            <el-input @input="getcdin" placeholder="长度(cm)"></el-input>
            <el-input @input="getkdin" placeholder="宽度(cm)"></el-input>
            <el-input @input="getgdin" placeholder="高度(cm)"></el-input>
            <el-input @input="getzllb" placeholder="重量(kg)"></el-input>
        </div>
        <br>
        <div>英寸/英镑：</div>
        <div class="cm">
            <el-input placeholder="长度(inch)" :value="cdin" @input="getcd"></el-input>
            <el-input placeholder="宽度(inch)" :value="kdin" @input="getkd"></el-input>
            <el-input placeholder="高度(inch)" :value="gdin" @input="getgd"></el-input>
            <el-input placeholder="重量(lb)" :value="zllb" @input="getzl"></el-input>
        </div>
        <br>
        <el-button type="primary" @click="getType">确定</el-button>
        <br>
        <br>
        <div>尺寸分段：{{this.type}}</div>
        <div>发货重量：{{this.fahuozl}}</div>
        <div>配送费用：{{this.fee}}</div>
        <div>合仓费用：{{this.hecang}}</div>
    </div>
</template>
<script>
const cm2inch = 2.54;//厘米to英寸
const kg2lb = 2.2;//千克to英镑

export default {
    data(){
        return {
            cdin:'',
            kdin:'',
            gdin:'',
            zllb:'',
            type:'',
            size:[],
            ss01:2.41,
            lss01:3.19,
            lss12:4.71,
            lss2o:4.71,
            lss2oxz:0.38,
            so:8.13,
            soxz:0.38,
            mo:9.44,
            moxz:0.38,
            lo:73.18,
            loxz:0.79,
            spo:137.32,
            spoxz:0.91,
            tijizl:0,
            fahuozl:0,
            maxzl:0,
            fee:0,
            hecang:0
        }
    },
    methods:{
        getType(){
            this.size = [];
            this.size.push(this.cdin*1);
            this.size.push(this.kdin*1);
            this.size.push(this.gdin*1);

            this.tijizl = this.get2point((this.cdin*this.kdin*this.gdin)/139);
            this.maxzl = this.zllb*1> this.tijizl*1?this.zllb*1:this.tijizl*1;

            let arr = this.size.sort(function(a,b){ 
                    return a-b; 
                });
            let cz = (arr[0]*1 + arr[1]*1)*2 + arr[2]*1;

            if(!(this.zllb <= 0.75 && arr[2] <= 15 && arr[1] <= 12 && arr[0] <= 0.75)){
                this.type = "大号标准尺寸"
                if(!(this.zllb <= 20 && arr[2] <= 18 && arr[1] <= 14 && arr[0] <= 8)){
                    this.type = '小号大件'
                    if(!(this.zllb <= 70 && arr[2] <= 60 && arr[1] <= 30 && cz <= 130)){
                        this.type = '中号大件'
                        if(!(this.zllb <= 150 && arr[2] <= 108 && cz <= 130)){
                            this.type = '大号大件'
                            if(!(this.zllb <= 150 && arr[2] <= 108 && cz <= 165)){
                                this.type = '特殊大件'
                            }
                        }
                    }
                }
            }else{
                this.type = "小号标准尺寸"
            }

            if(this.type == "小号标准尺寸"){
                this.fee = this.ss01
                this.hecangFee(1)
            }
            if(this.type == '大号标准尺寸'){
                let fahuo = Math.ceil(this.maxzl*1 + 0.25) 
                this.fahuozl = fahuo
                if(fahuo <= 1){
                    this.fee = this.lss01
                }else if(fahuo <= 2){
                    this.fee = this.lss12
                }else{
                    if(fahuo > 2){
                        this.fee = this.lss2o + this.lss2oxz*(fahuo-2)
                    }else{
                        this.fee = this.lss2o
                    }
                }
                this.hecangFee(1)
            }
            if(this.type == '小号大件'){
                let fahuo = Math.ceil(this.maxzl*1 + 1)
                if(fahuo > 2){
                    this.fee = this.so + this.soxz*(fahuo-2)
                }else{
                    this.fee = this.so
                }
                this.fahuozl = fahuo
                this.hecangFee(2)
            }
            if(this.type == '中号大件'){
                let fahuo = Math.ceil(this.maxzl*1 + 1)
                if(fahuo > 2){
                    this.fee = this.mo + this.moxz*(fahuo-2)
                }else{
                    this.fee = this.mo
                }
                this.fahuozl = fahuo
                this.hecangFee(2)
            }
            if(this.type == '大号大件'){
                let fahuo = Math.ceil(this.maxzl*1 + 1)
                if(fahuo > 90){
                    this.fee = this.lo + this.loxz*(fahuo-90)
                }else{
                    this.fee = this.lo
                }
                this.fahuozl = fahuo
                this.hecangFee(2)
            }
            if(this.type == '特殊大件'){
                let fahuo = Math.ceil(this.zllb*1 + 1)
                if(fahuo > 2){
                    this.fee = this.spo + this.spoxz*(fahuo-90)
                }else{
                    this.fee = this.spo
                }
                this.fahuozl = fahuo
                this.hecangFee(2)
            }
        },
        hecangFee(type){
            if(type == 1 ){
                if(this.zllb <= 1){
                    this.hecang = 0.3
                }else if(this.zllb <= 2){
                    this.hecang = 0.4
                }else{
                    this.hecang = 0.4 + (this.zllb - 2)*0.1
                }
            }else{
                if(this.zllb <= 5){
                    this.hecang = 1.3
                }else {
                    this.hecang = 1.3 + (this.zllb - 5)*0,2
                }
            }
        },
        getcdin(val){
            this.cdin = this.get2point(val/cm2inch)
        },
        getcd(val){
            this.cdin = val
        },
        getkdin(val){
            this.kdin = this.get2point(val/cm2inch)
        },
        getkd(val){
            this.kdin = val
        },
        getgdin(val){
            this.gdin = this.get2point(val/cm2inch)
        },
        getgd(val){
            this.gdin = val
        },
        getzllb(val){
            this.zllb = this.get2point(val/kg2lb)
        },
        getzl(val){
            this.zllb = val
        },
        get2point(str){
            return str.toFixed(2) == '0.00'?'':str.toFixed(2);
        }
    }
}
</script>
<style lang="less" scoped>
    .feeBox{
        width: 50%;
        .cm{
            display: flex;
            flex-direction: row;
        }
    }
</style>
